package com.sunday.member.utils;

import android.text.TextUtils;

import com.sunday.common.utils.MD5Utils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;


/**
 * Created by 刘涛 on 2017/5/25.
 */

public class SignUtil {

    //生成签名
    public static String getSign(String[] str1, String[] str2) {
        if (str1.length != str2.length) {
            return null;
        }
        HashMap<String,String> map=new HashMap<>();
        for (int i=0;i<str1.length;i++){
            map.put(str1[i],str2[i]);
        }
        Object[] key_arr=  map.keySet().toArray();
        Arrays.sort(key_arr);
        StringBuilder sign = new StringBuilder();
        for (Object keyItem:key_arr){
            String key= (String) keyItem;
            String value=map.get(key);
            if (!TextUtils.isEmpty(value))
            sign.append(key+"="+value+"&");

        }
        sign.deleteCharAt(sign.length() - 1);//去除最后一个&
        return MD5Utils.md5_32(sign.toString());
    }

}
